import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_wisave/Tools/NetworkService.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'HotEnergyView.dart';
import 'ContaminateView.dart';
import 'EnergyView.dart';
import 'WorkView.dart';
import '../../widgets/AppColors.dart';

class EnergyPage extends StatefulWidget {
  final int initialIndex;
  const EnergyPage({super.key, this.initialIndex = 0});

  @override
  State<EnergyPage> createState() => _EnergyPageState();
}

class _EnergyPageState extends State<EnergyPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  bool breakdown = true; // Add this line
  final NetworkService _networkService = NetworkService();

  //生命周期函数：当组件初始化的时候就会触发
  //输入inits可快速生成该方法
  @override
  void initState() {
    super.initState();
    _tabController = TabController(
        length: 4, vsync: this, initialIndex: widget.initialIndex);
    _networkService.setupInterceptors(context);
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent, // 状态栏颜色
    ));
    // 获取屏幕的宽度和高度
    final mediaQuery = MediaQuery.of(context);
    final screenWidth = mediaQuery.size.width;
    final screenHeight = mediaQuery.size.height;
    bool breakdown = true;

    return Scaffold(
      backgroundColor: AppColors.backgroundColor,
      appBar: AppBar(
        title: const Text('能环管理'),
        foregroundColor: AppColors.textPrimary,
        centerTitle: true,
        backgroundColor: Colors.transparent, // Make AppBar transparent
        flexibleSpace: Container(
          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/images/home/home_topbg.png'),
              fit: BoxFit.cover,
            ),
          ),
        ),
        bottom: PreferredSize(
          preferredSize: const Size.fromHeight(48), // Adjust height as needed
          child: Container(
            // color: Colors.red,
            child: TabBar(
              // isScrollable: true,
              indicatorColor: Colors.blue,
              indicatorWeight: 2,
              // indicatorPadding: const EdgeInsets.symmetric(horizontal: 16),
              indicatorSize: TabBarIndicatorSize.label,
              labelColor: TDTheme.of(context).grayColor12,
              unselectedLabelColor: TDTheme.of(context).grayColor8,
              labelStyle:
                  const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
              unselectedLabelStyle: const TextStyle(fontSize: 14),
              controller: _tabController,
              tabs: [
                Tab(
                    child: Text("全炉热效率",
                        style: TextStyle(
                            color: AppColors.textPrimary, fontSize: 13))),
                Tab(
                    child: Text("能耗指标",
                        style: TextStyle(
                            color: AppColors.textPrimary, fontSize: 13))),
                Tab(
                    child: Text("污染物排放",
                        style: TextStyle(
                            color: AppColors.textPrimary, fontSize: 13))),
                Tab(
                    child: Text("工况指标",
                        style: TextStyle(
                            color: AppColors.textPrimary, fontSize: 13))),
                // Tab(text: "全炉热效率"),
                // Tab(text: "能耗指标"),
                // Tab(text: "污染物排放"),
                // Tab(text: "工况指标"),
              ],
            ),
          ),
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          ListView(
            children: const [HotEnergyView()],
          ),
          ListView(
            children: const [EnergyView()],
          ),
          ListView(
            children: const [ContaminateView()],
          ),
          ListView(
            children: const [WorkView()],
          ),
        ],
      ),
    );
  }
}
